package com.ddwanglife.lamda;

import java.util.function.Consumer;
import java.util.function.Function;

class Dog{
    private String name = "哮天犬";
    private int food = 10;
    public static void wo(Dog dog){
        System.out.println(dog+"叫了");
    }
    public int eat(int num){
        System.out.println("吃了"+num);
        this.food -= num;
        return this.food;
    }
    public String toString(){
        return this.name;
    }
}
public class MethodRefrenceDemo {
    public static void main(String[] args) {
        //这个就是方法引用
        Consumer<String> c = System.out::println;
        c.accept("你好");
        //静态方法的方法引用
        Consumer<Dog> cc = Dog::wo;
        Dog dog = new Dog();
        cc.accept(dog);
        //非静态方法，使用对象实例的方法引用
        Function<Integer,Integer>  function = dog::eat;
        System.out.println("还剩下"+function.apply(3));
    }
}
